/**
 * 
 */
package com.ginger.rabbitmq.exchange.api.qos;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

/**
 * @Description: Ginger消费者
 * @author 姜锋
 * @date 2019年3月30日 下午12:14:46 
 * @version V1.0   
 *
 */
public class GingerConsumer extends DefaultConsumer{
	/** 日志对象 **/
	private final static Logger logger = LoggerFactory.getLogger(GingerConsumer.class);
	
	private Channel channel;

	/**
	 * @param channel
	 */
	public GingerConsumer(Channel channel) {
		super(channel);
		this.channel = channel;
	}

	/* （非 Javadoc）
	 * @see com.rabbitmq.client.DefaultConsumer#handleDelivery(java.lang.String, com.rabbitmq.client.Envelope, com.rabbitmq.client.AMQP.BasicProperties, byte[])
	 */
	@Override
	public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)
			throws IOException {
		logger.info("----- consumer message -----");
		logger.info("consumerTag:"+consumerTag);
		logger.info("envelope:"+envelope);
		logger.info("properties:"+properties);
		logger.info("body:"+new String(body));
		
		try {
			logger.warn("准备睡10秒");
			Thread.sleep(10000);
			logger.warn("睡了10秒,开始工作了");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		channel.basicAck(envelope.getDeliveryTag(), false);
	}
	
}
